//
//  interfaceClass.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/15.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef interfaceClass_hpp
#define interfaceClass_hpp

#include <stdio.h>
#include <iostream>

//接口类，没有成员变量，全是纯虚函数
//继承者必须实现所有的虚函数
class InterfaceLog {
    
public:
    
    virtual void openLog() = 0;
    virtual void writeLog() = 0;
    virtual void closeLog() = 0;
    
    virtual ~InterfaceLog(){};
};

class FileLog : public InterfaceLog {
    
public:
    
    FileLog(){
        std::cout << "File Log init\n";
    }
    
    virtual void openLog(){
        std::cout << "open FileLog\n";
    }
    virtual void writeLog(){
        std::cout << "write FileLog\n";
    }
    virtual void closeLog(){
        std::cout << "close FileLog\n";
    }
    
    virtual ~FileLog(){
        std::cout << "FileLog dealloc\n";
    }
    
};

class ScreenLog : public InterfaceLog {
    
    
public:
    
    ScreenLog(){
        std::cout << "Screen Log init\n";
    }
    
    virtual void openLog(){
        std::cout << "open ScreenLog\n";
    }
    virtual void writeLog(){
        std::cout << "write ScreenLog\n";
    }
    virtual void closeLog(){
        std::cout << "close ScreenLog\n";
    }
    virtual ~ScreenLog(){
        std::cout << "ScreenLog dealloc\n";
    }
};

class TestInterface {
    FileLog m_fileLog;
    ScreenLog m_scerrnLog;
    
public:
    
    TestInterface(){
        
    }
    
    void printLog(InterfaceLog &log){
        log.openLog();
    }
    
};


/*
 
 FileLog file;
 ScreenLog screen;
 
 TestInterface interface;
 interface.printLog(screen);
 
 */

class post : public InterfaceLog {
    
    
public:
    
   virtual void addRef() = 0;
    
    post();

    virtual ~post();

protected:

    //必须实现，否则无法实例化抽象类
    virtual void openLog();
    virtual void writeLog();
    virtual void closeLog();
    
};

class post2 : public post {
    
public:
    
    virtual void addRef(){
        printf("GGGGG");
    }
    
};

#endif /* interfaceClass_hpp */
